#ifndef _UTILS_INCLUDED_
#define _UTILS_INCLUDED_
#include <error.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <sys/time.h>

// 返回与 tcpdump 默认输出一致的时间，格式是 xx:xx:xx.yyyzz
const char*
gf_time() {
    struct timeval tv;
    if (gettimeofday(&tv, NULL) < 0)
        error_dump("fail to gettimeofday");

    static char buf[30];
    const char *ptr = ctime(&tv.tv_sec);
    strcpy(buf, &ptr[11]);
    snprintf(buf + 8, sizeof(buf) - 8, ".%06ld", tv.tv_usec);
    return buf;
}

#endif // _UTILS_INCLUDED_
